/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sg.edu.nus.iss.billing.ui.gui;

import java.awt.Desktop;
import java.beans.PropertyVetoException;

import javax.swing.JOptionPane;

import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.service.login.Administrator;
import sg.edu.nus.iss.billing.ui.controller.*;
import sg.edu.nus.iss.billing.vo.customer.*;
import sg.edu.nus.iss.billing.vo.account.*;
/**
 *
 * @author Administrator
 */
public class CustomerWindow extends javax.swing.JInternalFrame {

    /**
     * Creates new form CustomerWindow
     */
	private OneBillingSystem onebillingsystem;
	//private CustomerComplaintWindow custcompwin;
	private CustomerVO custviewobj;
	private AddressVO addressviewobj;
	private AccountVO accviewobj;
	private String accountNo;
	int comingFrom =0;
	
    public CustomerWindow(OneBillingSystem onebillingsystem,int comingFrom) {
    	this.onebillingsystem = onebillingsystem;
    	this.comingFrom = comingFrom;
    	
        initComponents();
        SetButtons();
    }

  
    private void SetButtons() {
    	System.out.println("ROLE IS "+onebillingsystem.getUser().getLoginVO().getUserRole());
		if(onebillingsystem.getUser() instanceof Administrator){
			
			btnSave.setVisible(true);
		}
		else{
			btnSave.setVisible(false);
		}
		
	}


	/**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

    	 jPanel1 = new javax.swing.JPanel();
         btnSearch = new javax.swing.JButton();
         txtAccountno = new javax.swing.JTextField();
         jLabel2 = new javax.swing.JLabel();
         jPanel2 = new javax.swing.JPanel();
         jLabel3 = new javax.swing.JLabel();
         jLabel4 = new javax.swing.JLabel();
         txtCustName = new javax.swing.JTextField();
         txtNRFCFIN = new javax.swing.JTextField();
         jLabel13 = new javax.swing.JLabel();
		 txtCustName = new javax.swing.JTextField();
         txtID = new javax.swing.JTextField();
         jLabel5 = new javax.swing.JLabel();
         jLabel7 = new javax.swing.JLabel();
         txtAddressLine1 = new javax.swing.JTextField();
         txtAdressLine2 = new javax.swing.JTextField();
         jLabel8 = new javax.swing.JLabel();
         txtAddressPostalCode = new javax.swing.JTextField();
         jLabel9 = new javax.swing.JLabel();
         txtCity = new javax.swing.JTextField();
         lblCountry = new javax.swing.JLabel();
         jLabel1 = new javax.swing.JLabel();
         jLabel6 = new javax.swing.JLabel();
         txtContactNo = new javax.swing.JTextField();
         jLabel11 = new javax.swing.JLabel();
         txtInterest = new javax.swing.JTextField();
         jLabel12 = new javax.swing.JLabel();
         chkActive = new javax.swing.JCheckBox();
         txtCountry = new javax.swing.JTextField();
         btnBilling = new javax.swing.JButton();
         btnComplaint = new javax.swing.JButton();
         btnSubscriptions = new javax.swing.JButton();
         btnSave = new javax.swing.JButton();
         btnClose = new javax.swing.JButton();
         txtsrcNricFin = new javax.swing.JTextField();
         jLabel10 = new javax.swing.JLabel();
         btnClear = new javax.swing.JButton();
         
         setClosable(true);
         setTitle("Customer Details");
         txtID.setEditable(true);
         
         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))));

         btnSearch.setText("Search");
         
         txtAccountno.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
         txtAccountno.setName("txtAccountno");
         
         
         jLabel2.setText("Account No");
         
         
         txtID.enable(false);
			
         jLabel10.setText("NRIC/FIN");
         btnClear.setText("Clear");

         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
         jPanel1.setLayout(jPanel1Layout);
         jPanel1Layout.setHorizontalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel2)
                     .addComponent(jLabel10))
                 .addGap(40, 40, 40)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                     .addComponent(txtAccountno, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                     .addComponent(txtsrcNricFin))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                 .addComponent(btnSearch)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addComponent(btnClear, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addContainerGap())


         );
         jPanel1Layout.setVerticalGroup(
             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel1Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel10)
                     .addComponent(txtsrcNricFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(btnSearch)
                     .addComponent(txtAccountno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(jLabel2)
                     .addComponent(btnClear))
                 .addContainerGap())
         );

         jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))));

         jLabel3.setText("Name");

         jLabel4.setText("NRIC/FIN");

         jLabel13.setText("Id");

         jLabel5.setText("Line 1");

         jLabel7.setText("Line 2");

         jLabel8.setText("Postal code");

         jLabel9.setText("City/State");

         lblCountry.setText("Country");

         jLabel1.setText("Address Detail");

         jLabel6.setText("Contact No");

         jLabel11.setText("Interest");

         jLabel12.setText("Status");

         chkActive.setText("Inactive");

         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
         jPanel2.setLayout(jPanel2Layout);
         jPanel2Layout.setHorizontalGroup(
             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel2Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                             .addComponent(jLabel11)
                             .addGap(120, 120, 120))
                         .addGroup(jPanel2Layout.createSequentialGroup()
                             .addComponent(jLabel12)
                             .addGap(128, 128, 128)))
                     .addGroup(jPanel2Layout.createSequentialGroup()
                         .addComponent(jLabel1)
                         .addGap(302, 302, 302))
                     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addGroup(jPanel2Layout.createSequentialGroup()
                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                 .addComponent(jLabel3)
                                 .addComponent(jLabel4)
                                 .addComponent(jLabel13)
                                 .addComponent(jLabel5)
                                 .addComponent(jLabel7)
                                 .addComponent(lblCountry, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                             .addGap(41, 41, 41)
                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                 .addComponent(txtID)
                                 .addComponent(txtCustName)
                                 .addComponent(txtAddressLine1)
                                 .addComponent(txtAdressLine2)
                                 .addComponent(txtCity)
                                 .addComponent(txtCountry)
                                 .addComponent(txtContactNo)
                                 .addComponent(txtInterest)
                                 .addGroup(jPanel2Layout.createSequentialGroup()
                                     .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                         .addComponent(txtNRFCFIN, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                         .addComponent(txtAddressPostalCode, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                         .addComponent(chkActive))
                                     .addGap(0, 0, Short.MAX_VALUE)))
                             .addGap(81, 81, 81))
                         .addGroup(jPanel2Layout.createSequentialGroup()
                             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                 .addComponent(jLabel6)
                                 .addComponent(jLabel8)
                                 .addComponent(jLabel9))
                             .addContainerGap()))))
         );
         jPanel2Layout.setVerticalGroup(
             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(jPanel2Layout.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addComponent(jLabel13)
                     .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel3)
                     .addComponent(txtCustName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel4)
                     .addComponent(txtNRFCFIN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                 .addComponent(jLabel1)
                 .addGap(6, 6, 6)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(txtAddressLine1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(jLabel5))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel7)
                     .addComponent(txtAdressLine2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel8)
                     .addComponent(txtAddressPostalCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel9)
                     .addComponent(txtCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(lblCountry)
                     .addComponent(txtCountry, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel6)
                     .addComponent(txtContactNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel11)
                     .addComponent(txtInterest))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(jLabel12)
                     .addComponent(chkActive))
                 .addContainerGap())
         );
         
         btnBilling.setText("Billing");
         btnBilling.setToolTipText("");

         btnComplaint.setText("Complaint");

         btnSubscriptions.setText("Subscriptions");

         btnSubscriptions.setEnabled(false);
         btnComplaint.setEnabled(false);
         btnBilling.setEnabled(false);
         
         btnSave.setText("Save");

         btnClose.setText("Close");

         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                         .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                         .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                             .addGroup(layout.createSequentialGroup()
                                 .addComponent(btnBilling)
                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                 .addComponent(btnComplaint)
                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                 .addComponent(btnSubscriptions))
                             .addComponent(btnSave))
                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                         .addComponent(btnClose)))
                 .addContainerGap())
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(btnBilling)
                     .addComponent(btnComplaint)
                     .addComponent(btnSubscriptions))
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                     .addComponent(btnClose)
                     .addComponent(btnSave))
                 .addContainerGap())
         );
         
         //Implement listeners--------------------------------------------------------------------------------------------
         btnSearch.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 btnSearchPerformed(evt);
             }
         });
         
         btnSave.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	  btnSaveActionPerformed(evt);
             }
         });
         
          btnBilling.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 btnBillingActionPerformed(evt);
             }
         });
          
         btnComplaint.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	btnComplaintActionPerformed(evt);
             }
         });
         
         btnSubscriptions.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 btnSubscriptionActionPerformed(evt);
             }
         });
         
         btnClose.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 try {
  						setClosed(true);
	  				} catch (PropertyVetoException e) {
	  					// TODO Auto-generated catch block
	  					e.printStackTrace();
	  				}
             }
         });
         
		btnClear.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 txtAccountno.setText("");
            	 txtsrcNricFin.setText("");
            	 txtCustName.setText("");
            	 txtNRFCFIN.setText("");
            	 txtAddressLine1.setText("");
            	 txtAddressPostalCode.setText("");
            	 txtAdressLine2.setText("");
            	 txtCity.setText("");
            	 txtContactNo.setText("");
            	 txtCountry.setText("");
            	 txtInterest.setText("");	
            	 txtID.setText("");
            	 chkActive.setSelected(false);
             }
         });
        
            pack();
            if (comingFrom ==1)
            {
           	 	jPanel1.hide();
           	 	btnBilling.setEnabled(false);
           	 	btnComplaint.setEnabled(false);
           	 	txtID.setText("[Auto ID]");
           	 	this.pack();

        
            }
        }// </editor-fold>

    private void btnSearchPerformed(java.awt.event.ActionEvent evt) {
    		bindCustomerDetails();
    } 
	
	private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
		try{
        	custviewobj = new CustomerVO();
        	addressviewobj = new AddressVO();
        	Formvalidation frmvalid = new Formvalidation();
			
			if (frmvalid.validateNumber(txtContactNo.getText()) == false){
				JOptionPane.showMessageDialog(null,"Please enter the contact no.","Validation",JOptionPane.ERROR_MESSAGE);
				return;
			}
			
        	//Account 
        	accviewobj = new AccountVO(txtAccountno.getText().trim());
        	
        	//Customer view
        	custviewobj.setAccount(accviewobj);
        	//custviewobj.setAccountId(txtAccountno.getText().trim());
        	custviewobj.setCustomerNme(txtCustName.getText().trim());
        	custviewobj.setNric(txtNRFCFIN.getText().trim());
        	
        	//Address view
        	addressviewobj.setLine1(txtAddressLine1.getText().trim());
        	addressviewobj.setLine2(txtAdressLine2.getText().trim());
        	addressviewobj.setPostalCode(txtAddressPostalCode.getText().trim());
        	addressviewobj.setCity(txtCity.getText().trim());
			   	addressviewobj.setCountry(txtCountry.getText().trim());
        	custviewobj.setAddress(addressviewobj);
        	
        	custviewobj.setContactNo(txtContactNo.getText().trim());
        	custviewobj.setInterest(txtInterest.getText().trim());
        	
        	if (comingFrom==0){
        	if (chkActive.isSelected()){
        		custviewobj.getAccount().setStatus(Util.ACCOUNT_STATUS_INACTIVE);
        		onebillingsystem.deregisterCustomer(custviewobj);
        	}
        	else{
        		custviewobj.getAccount().setStatus(Util.ACCOUNT_STATUS_ACTIVE);
        		onebillingsystem.deregisterCustomer(custviewobj);
        	}
        	}
        	
        	System.out.println("Customer Reg Start Point : [1]");
        	
        	String acctNo ;
        	
        	if (comingFrom==1){
        		acctNo=  onebillingsystem.registerCustomer(custviewobj);
        		txtID.setText(acctNo);
	        	if (acctNo.length()> 0){
	        		btnSubscriptions.setEnabled(true);
	        		JOptionPane.showMessageDialog(null,"Customer registration successfully completed.","Success",JOptionPane.INFORMATION_MESSAGE);
	        		btnBilling.setEnabled(true);
	           	 	btnComplaint.setEnabled(true);
	        	} else {
	        		JOptionPane.showMessageDialog(null,"Unable to create new customer details.","Error",JOptionPane.ERROR_MESSAGE);
	        	}
        	} else {
        		if (onebillingsystem.updateCustomerDetails(custviewobj)){
	        		JOptionPane.showMessageDialog(null,"Customer details update successfully completed.","Operation Statue",JOptionPane.INFORMATION_MESSAGE);
	        	} else {
	        		JOptionPane.showMessageDialog(null,"Unable to update customer details.","Operation Statue",JOptionPane.ERROR_MESSAGE);
	        	}
        	}
        	
        		
        } catch (Exception e){
        	JOptionPane.showMessageDialog(null,"Unable to update customer details.","Operation Statue",JOptionPane.ERROR_MESSAGE);
    
        	e.printStackTrace();
        }
	}

        	

	
	private void btnBillingActionPerformed(java.awt.event.ActionEvent evt) {
        try{
        	accountNo = txtID.getText().trim();
        	ViewBill viewBill = new ViewBill(onebillingsystem, accountNo);
        	onebillingsystem.getMainForm().getDesktop().add(viewBill);
        	viewBill.show();
        } catch (Exception e){
        	
        }
	}
	
	private void btnComplaintActionPerformed(java.awt.event.ActionEvent evt) {
		try{
			
        	CustomerComplaintWindow custcompwin = new CustomerComplaintWindow(onebillingsystem,txtID.getText());
        	//onebillingsystem.getMainForm().add(custcompwin);
        	onebillingsystem.getMainForm().getDesktop().add(custcompwin);
        	custcompwin.show();
        	
        } catch (Exception e){
        	
        }
	}
	
	private void btnSubscriptionActionPerformed(java.awt.event.ActionEvent evt) {
		try{
			
			if(txtID.getText()!=null|| txtID.getText()!="" )
			{
			 TabbedFrame frame = new TabbedFrame("Add Subscription", onebillingsystem,txtID.getText());
			  DigitalVoicePanel digitalvoicepanel = new DigitalVoicePanel(frame, onebillingsystem);
			  frame.getTab().add("Digital Voice", digitalvoicepanel);
			  MobileVoicePanel mobilevoicepanel = new MobileVoicePanel(frame, onebillingsystem);
			  frame.getTab().add("Mobile Voice", mobilevoicepanel);
			  CableTVPanel cabletvpanel = new CableTVPanel(frame, onebillingsystem);
			  frame.getTab().add("Cable TV", cabletvpanel);
			  frame.setSize(400,400);
			  onebillingsystem.getMainForm().getDesktop().add(frame);
			  frame.setVisible(true);
			  frame.setBounds(450, 0, 400, 550);
			}
			else
			{
	        	JOptionPane.showMessageDialog(null,"Please retrieve customer info first","Customer Not Found",JOptionPane.ERROR_MESSAGE);
	        	
			}
        } catch (Exception e){
        	System.out.println(e.toString());
        }
	}
	
	private void bindCustomerDetails(){
		
			if (txtsrcNricFin.getText().equals("") && txtAccountno.getText().equals("")){
				JOptionPane.showMessageDialog(null,"Please enter the NRIC/Account number.","Customer Details",JOptionPane.INFORMATION_MESSAGE);
			}
		
			accviewobj = new AccountVO(txtAccountno.getText().trim());
			custviewobj = new CustomerVO();
			custviewobj.setNric(txtsrcNricFin.getText().trim());
			
			addressviewobj = new AddressVO();
			
			if (txtsrcNricFin.getText().equals("")){
				System.out.println("View Customer By Account No :: ");
				custviewobj = onebillingsystem.viewCustomerDetailByACCNo(accviewobj);
			} else {
				System.out.println("View Customer By NRIC :: ");
				custviewobj = onebillingsystem.viewCustomerDetailByNRIC(custviewobj);
			}

			//txtID.setText(custviewobj.getCustomerId().trim());
			if(custviewobj != null)
			{
			txtCustName.setText(custviewobj.getCustomerNme().trim());
			//txtAccountno.setText(custviewobj.getAccount().getAccountNo());
			txtID.setText(custviewobj.getAccount().getAccountNo());
			txtNRFCFIN.setText(custviewobj.getNric().trim());
			
			txtAddressLine1.setText(custviewobj.getAddress().getLine1().trim());
			txtAdressLine2.setText(custviewobj.getAddress().getLine2().trim());
			txtAddressPostalCode.setText(custviewobj.getAddress().getPostalCode().trim());
			txtCity.setText(custviewobj.getAddress().getCity().trim());
			txtCountry.setText(custviewobj.getAddress().getCountry());
			
			txtContactNo.setText(custviewobj.getContactNo());
			txtInterest.setText(custviewobj.getInterest().trim());
			btnSubscriptions.setEnabled(true);
			btnBilling.setEnabled(true);
			
			if (custviewobj.getAccount().getStatus().equalsIgnoreCase(Util.ACCOUNT_STATUS_ACTIVE)){
				chkActive.setSelected(false);
				btnComplaint.setEnabled(true);
			}
			else {
				chkActive.setSelected(true);
				btnComplaint.setEnabled(false);
			}
			
			}
			else
			{
				JOptionPane.showMessageDialog(this,"Customer cannot found.","Not Found",JOptionPane.INFORMATION_MESSAGE);
			}

	}
	
	private String fieldValidations(){
		String errorMessage = "";
		try{
			Formvalidation frmvalid = new Formvalidation();
			
			if (frmvalid.validateNumber(txtContactNo.getText())){
				
			}
			
		}catch(Exception e){
			
		}
		return errorMessage;
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton btnBilling;
    private javax.swing.JButton btnClear;
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnComplaint;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSearch;
    private javax.swing.JButton btnSubscriptions;
    private javax.swing.JCheckBox chkActive;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblCountry;
    private javax.swing.JTextField txtAccountno;
    private javax.swing.JTextField txtAddressLine1;
    private javax.swing.JTextField txtAddressPostalCode;
    private javax.swing.JTextField txtAdressLine2;
    private javax.swing.JTextField txtCity;
    private javax.swing.JTextField txtContactNo;
    private javax.swing.JTextField txtCountry;
    private javax.swing.JTextField txtCustName;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtInterest;
    private javax.swing.JTextField txtNRFCFIN;
    private javax.swing.JTextField txtsrcNricFin;
    private javax.swing.JLabel jLabel10;
    // End of variables declaration//GEN-END:variables
}
